home *** CD-ROM | disk | FTP | other *** search
- // HostHelper.cpp: implementation of the CHostHelper class.
- //
- //////////////////////////////////////////////////////////////////////
-
- #include "stdafx.h"
- #include "HostHelper.h"
-
- /////////////////////////////////////////////////////////////////////////////
- // CTransform_ExportProject
- //Comment:
- //EngineHost IDispatch interface
- //
- // interface IXmlHandlerHost : IDispatch
- // {
- // [id(1), helpstring("method InitNew")] HRESULT InitNew([in] IUnknown *pInternalHost);
- // [id(2), helpstring("method NotifyMessage")] HRESULT NotifyMessage([in] BSTR bstrMsg);
- // [id(3), helpstring("method NotifyError")] HRESULT NotifyError([in] BSTR bstrErrorMsg);
- // [id(4), helpstring("method NotifyProgressTotal")] HRESULT NotifyProgressTotal([in] UINT nTotalStep);
- // [id(5), helpstring("method NotifyProgress")] HRESULT NotifyProgress([in] UINT nCurrentStep);
- // [id(6), helpstring("method GetProperty")] HRESULT GetProperty([in] BSTR bstrName, [out, retval] BSTR *pbstrValue);
- // };
-
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
-
- CHostHelper::CHostHelper(IDispatch *a_pDispatch)
- :m_psDispatch(a_pDispatch)
- {
- ASSERT(a_pDispatch != NULL);
- }
-
- CHostHelper::~CHostHelper()
- {
-
- }
-
- BOOL CHostHelper::NotifyError(LPCTSTR a_pszError)
- {
- DISPID nDispId = -1;
- if ((CheckGetDispatchId("NotifyError",nDispId)) &&
- (nDispId != -1))
- {
- CComVariant var = a_pszError;
- HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
- return (hr == S_OK)? TRUE: FALSE;
- }
- return FALSE;
- }
-
- BOOL CHostHelper::NotifyMessage(LPCTSTR a_pszMessage)
- {
- DISPID nDispId = -1;
- if ((CheckGetDispatchId("NotifyMessage",nDispId)) &&
- (nDispId != -1))
- {
- CComVariant var = a_pszMessage;
- HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
- return (hr == S_OK)? TRUE: FALSE;
- }
- return FALSE;
- }
-
- BOOL CHostHelper::NotifyProgress(UINT a_nCurrentStep)
- {
- DISPID nDispId = -1;
- if ((CheckGetDispatchId("NotifyProgress",nDispId)) &&
- (nDispId != -1))
- {
- CComVariant var = (LONG)a_nCurrentStep;
- HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
- return (hr == S_OK)? TRUE: FALSE;
- }
- return FALSE;
-
- }
-
- BOOL CHostHelper::NotifyProgressTotal(UINT a_nTotalStep)
- {
- DISPID nDispId = -1;
- if ((CheckGetDispatchId("NotifyProgressTotal",nDispId)) &&
- (nDispId != -1))
- {
- CComVariant var = (LONG)a_nTotalStep;
- HRESULT hr = m_psDispatch.Invoke1(nDispId,&var);
- return (hr == S_OK)? TRUE: FALSE;
- }
- return FALSE;
- }
-
- BOOL CHostHelper::GetProperty(LPCTSTR a_pszName, BSTR *a_pbstrValue)
- {
- DISPID nDispId = -1;
- if ((CheckGetDispatchId("GetProperty",nDispId)) &&
- (nDispId != -1))
- {
- CComVariant var = a_pszName;
- CComVariant varRet;
- HRESULT hr = m_psDispatch.Invoke1(nDispId,&var,&varRet);
- if (hr == S_OK)
- {
- if (varRet.vt = VT_BSTR)
- {
- CString strTmp = varRet.bstrVal;
- if (a_pbstrValue != NULL)
- *a_pbstrValue = strTmp.AllocSysString();
- }
- }
- return (hr == S_OK)? TRUE: FALSE;
- }
- return FALSE;
- }
-
- BOOL CHostHelper::CheckGetDispatchId(LPCTSTR a_pszMethodName, DISPID &ar_nDispId)
- {
- if (m_psDispatch != NULL)
- {
- //Check the host has IDispatch interface
- CComPtr<IDispatch> psDispatch;
- if ((m_psDispatch->QueryInterface(__uuidof(IDispatch),(void**)&psDispatch) == S_OK) &&
- (psDispatch != NULL))
- {
- //find method dispatch id
- CComBSTR bstrMethodName;
- bstrMethodName = a_pszMethodName;
- HRESULT hr = m_psDispatch.GetIDOfName(bstrMethodName, &ar_nDispId);
- if (SUCCEEDED(hr))
- return TRUE;
- }
- }
- return FALSE;
- }
-
-